<template>
  <div>
    <el-form
      ref="form"
      :model="userinfo"
      :rules="rules"
      label-width="80px"
      :inline="false"
      size="normal"
    >
      <el-form-item label="部门" prop="departmentName">
        <el-input v-model="userinfo.departmentName" style="width: 300px" />
      </el-form-item>
      <el-form-item label="入职时间" prop="correctionTime">
        <el-date-picker
          v-model="userinfo.correctionTime"
          type="date"
          class="inputW"
          value-format="yyyy-MM-dd"
        />
      </el-form-item>
      <el-form-item label="员工头像" size="normal" />
      <UploadImg
        :imgurl="userinfo.staffPhoto"
        @upload-img="userinfo.staffPhoto = $event"
      />
      <el-form-item>
        <el-button type="primary" @click="sunbmitEdit">提交</el-button>
        <el-button @click="$router.back()">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { saveUserDetailById } from '@/api/employees'
import { mapActions } from 'vuex'
export default {
  props: {
    userinfo: {
      type: Object,
      default: () => ({})
    }
  },
  data () {
    return {
      userfrom: {},
      rules: {
        departmentName: [
          { required: true, message: '请输入部门名称', trigger: 'blur' }
        ],
        correctionTime: [
          { required: true, message: '请输入入职时间', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    ...mapActions('user', ['getUserInfoAction']),
    async sunbmitEdit () {
      console.log('提交')
      try {
        await saveUserDetailById(this.userinfo)
        this.$router.back()
        this.$message.success('修改用户信息成功')
        this.getUserInfoAction()
      } catch (error) {
        console.log(error)
      }
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
